package com.lca.lca_yuekao.controller;


import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lca.lca_yuekao.entity.Denglu;
import com.lca.lca_yuekao.service.DengluService;
import org.apache.poi.util.StringUtil;
import org.springboot.bw.entity.RbacUser;
import org.springboot.bw.struct.Result;
import org.springboot.bw.struct.ResultLogin;
import org.springboot.bw.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 关注公众号：lca
 * @since 2022-07-12
 */
@RestController
@RequestMapping("/denglu")
public class DengluController {

    @Resource
    DengluService dengluService;

    @PostMapping("login")
    public Result login(@PathVariable("name") Integer name,
                        @PathVariable("password") Integer password){
        QueryWrapper<Denglu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",name);
        queryWrapper.eq("password",password);
        Denglu one = this.dengluService.getOne(queryWrapper);
        return Result.ok();
    }

    @RequestMapping("getCode.png")
    public void getcode(HttpServletResponse response, String codeKey){
        response.setHeader("Content-type","imgage.jpeg");
        CircleCaptcha captcha = CaptchaUtil.createCircleCaptcha(200, 100, 4, 4);
        System.out.println("111正码是"+captcha.getCode());
    }

    @PostMapping("mylogin")
    public ResultLogin mylogin(@RequestBody()RbacUser user, String codeKey,String code){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        return null;
    }
}
